package com.lanou.elh.sysmanage.item_manage.web.controller;

import com.lanou.elh.sysmanage.item_manage.ItemResult;
import com.lanou.elh.sysmanage.item_manage.Result;
import com.lanou.elh.sysmanage.item_manage.ResultUtil;
import com.lanou.elh.sysmanage.item_manage.entity.Item;
import com.lanou.elh.sysmanage.item_manage.service.ItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(description = "商品列表信息")
public class ItemController {

    @Autowired
    private ItemService itemService;

    @GetMapping("/item/{itemId}")
    @ApiOperation(value = "通过ID获取商品")
    public Result<Item> getItemById(@PathVariable Long itemId) {
        Item item = itemService.getItemById(itemId);
        return new ResultUtil<Item>().setData(item);
    }


    @GetMapping("/item/list")
    @ApiOperation(value = "获取商品列表")
    public ItemResult<List<Item>> getItemList(Integer draw) {

        List<Item> itemList = itemService.getItemList();
        Integer itemCount = itemService.getItemCount();

        return new ResultUtil().setData(itemList, draw, itemCount, itemCount);
    }



}
